package com.gnerv.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gnerv.cms.entity.Tag;
import com.gnerv.cms.mapper.TagMapper;
import com.gnerv.cms.service.ITagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * CMS平台-标签表 服务实现类
 * </p>
 *
 * @author Gnerv LiGen
 * @since 2019-07-01
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements ITagService {

    @Autowired
    TagMapper tagMapper;

    @Override
    public boolean createTag(Tag tag) {
        tagMapper.insert(tag);
        return true;
    }

    @Override
    public boolean deleteTag(String bId) {
        tagMapper.delete(new QueryWrapper<>(new Tag(bId)));
        return true;
    }

    @Override
    public boolean updateTag(Tag tag) {
        tagMapper.update(tag, new QueryWrapper<>(new Tag(tag.getbId())));
        return true;
    }

    @Override
    public Tag selectTag(String bId) {
        Tag tag = tagMapper.selectOne(new QueryWrapper<>(new Tag(bId)));
        return tag;
    }

    @Override
    public List<Tag> listTag(Tag tag) {
        List<Tag> tags = tagMapper.selectList(new QueryWrapper<>(tag));
        return tags;
    }
}
